import { CrumbsT, UserInfo, setAutoId } from "../dictionary/dictionary";
const initState = {
  user: {
    // 用户信息
    token: "",
    data: {
      user: "",
      auth: 1,
    },
  },

  loginStore: 0, // 登录状态 0 => 未登录  1 => 已登录
  OpenKeys: "sub1", // 当前展开的是哪一列
  SelectedKeys: "0", // 当前选中的是哪一个
  visitList: {} // 存放权限
};

let Reducer = (state = initState, action) => {
  let data = JSON.parse(JSON.stringify(state));
  switch (action.type) {
    // 面包屑切换导航
    case CrumbsT:
      data.OpenKeys = action.active[0];
      data.SelectedKeys = action.active[1];
      return data;
    // 获取用户信息
    case UserInfo:
      data.user = action;
      data.loginStore = 1;
      data.visitList = action.data.visitList[0];
      return data;
    // 自动登录
    case setAutoId:
      data.user.token = action.data.token;
      data.visitList = action.data.visitList[0];
      data.loginStore = 1;
      return data;
    default:
      return state;
  }
};

export default Reducer;
